﻿using Sustainalytics.Entities;
using System;

namespace Sustainalytics.Governance.BusinessLogic.Model
{
    public class GovernanceInsightDto
    {
        public static GovernanceInsightDto FromGovernanceInsight(GovernanceInsight gInsight, string host)
        {
            if (host.Contains("+"))
                host = host.Replace("+", "localhost");


            if (!host.EndsWith("/"))
                host += "/";
            var hostUri = new Uri(host);

            var result = new GovernanceInsightDto()
            {
                Id = gInsight.Id,
                CreatedDate = gInsight.CreatedDate,
                CreatedBy = gInsight.CreatedBy,
                PublicationDate = gInsight.PublicationDate,
                Title = gInsight.Title
            };

            if (gInsight.FileId != Guid.Empty)
            {
                result.FileId = gInsight.FileId;
                result.FileUrl = (new Uri(hostUri, hostUri.LocalPath + "api/v1/files/" + gInsight.FileId)).ToString().ToLowerInvariant();
            }

            return result;
        }

        public Guid Id { get; set; }
        public Guid CompanyId { get; set; }
        public DateTime CreatedDate { get; set; }
        public string CreatedBy { get; set; }
        public DateTime PublicationDate { get; set; }
        public string Title { get; set; }
        public Guid FileId { get; set; } // insight pdf file id
        public string FileUrl { get; set; }
        public string FileName { get; set; }

    }
}
